var adcontentForm = function () {
    return {
        //main function to initiate the module
        init: function () {
			$.validator.addMethod(
				"regex", 
				function(value, element, params) {
					var reg = new RegExp(params);
					//console.log('value:'+value+' , params: '+params+' , result: '+reg.test(value));
					return reg.test(value);
				}, 
				"Did not pass the regular verification"
			);

            var form1 = $('#adcontentForm');
            var error1 = $('.alert-error', form1);
            var success1 = $('.alert-success', form1);

            form1.validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-inline', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                ignore: "",
                rules: {
                    title: {
                        maxlength:40,
                        required: true,
                    },
					onetitle: {
                        maxlength:40,
                        required: true,
                    },
					twotitle: {
                        maxlength:40,
                        required: true,
                    },
					threetitle: {
                        maxlength:40,
                        required: true,
                    },
					onenum: {
                        required: true,
						number:true,
                    },
					twonum: {
                        required: true,
						number:true,
                    },
					threenum: {
                        required: true,
						number:true,
                    },
                    ctitle: {
                        maxlength:40,
                        required: true,
                    },
					prize: {
						maxlength:40,
						required: true,
					},
					nums: {
						required: true,
						number:true,
					},
                    totalnums: {
						number:true,
                        required: true,
                    },
                    daynums: {
						number:true,
						required: true,
                    },
                    description: {
						maxlength:255,
						required: true,
                    },
                    cdescription: {
						maxlength:255,
						required: true,
                    },
                },
				messages: {
					title: {
						required:  vMessage.title_required,
						maxlength: vMessage.title_maxlength
					},
					onetitle: {
						required:  vMessage.prize_required,
						maxlength: vMessage.title_maxlength
					},
					twotitle: {
						required:  vMessage.prize_required,
						maxlength: vMessage.title_maxlength
					},
					threetitle: {
						required:  vMessage.prize_required,
						maxlength: vMessage.title_maxlength
					},
					ctitle: {
						required:  vMessage.title_required,
						maxlength: vMessage.title_maxlength
					},
					nums: {
						required: vMessage.nums_required,
						number  : vMessage.mustnums_required,
					},
					onenum: {
						required: vMessage.nums_required,
						number  : vMessage.mustnums_required,
					},
					twonum: {
						required: vMessage.nums_required,
						number  : vMessage.mustnums_required,
					},
					threenum: {
						required: vMessage.nums_required,
						number  : vMessage.mustnums_required,
					},
					prize: {
						required: vMessage.prize_required,
						number  : vMessage.mustnums_required,
					},
					totalnums: {
						required:  vMessage.totalnums_required,
						number  :  vMessage.mustnums_required,
					},
					daynums: {
						required:  vMessage.daynums_required,
						number  :  vMessage.mustnums_required,
					},
					description: {
						required:  vMessage.description_required,
						regex: vMessage.description_regex
					},
					cdescription: {
						required:  vMessage.description_required,
						regex: vMessage.description_regex
					},
				},
                invalidHandler: function (event, validator) {
                    success1.hide();
                    error1.show();
                    App.scrollTo(error1, -200);
                },

                highlight: function (element) {
                    $(element).closest('.help-inline').removeClass('ok');
                    $(element).closest('.control-group').removeClass('success').addClass('error');
                },

                unhighlight: function (element) {
                    $(element).closest('.control-group').removeClass('error');
                },
            });
        }

    };

}();